package com.leetcode.June;

/**
 * @Description: 搜索二维矩阵
 * @Author: Mr.Fxy
 * @CreateTime: 2024-07-26 09:58
 */
public class seaMatrix {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int l = matrix[0].length;
        if (m == 0 || l == 0) {
            return false;
        }
        for (int i = 0; i < m; i++) {
            int low = 0;
            int high = l - 1;
            while (low<=high){
                int mid=(low+high)/2;
                if (matrix[i][mid]==target){
                    return true;
                }else if (matrix[i][mid]<target){
                    low+=1;
                }else{
                    high-=1;
                }
            }
        }
        return false;
    }
}
